<section id="torch-toolbar">
  <div class="torch-container">
    <.link href={~p"<%= schema.route_prefix %>/new"} class="torch-button">New <%= schema.human_singular %></.link>
  </div>
</section>
<section id="torch-index-content">
  <div class="torch-container">
    <section id="torch-filters">
      <h3>Find <%= schema.human_plural %></h3>
      <%%= form_tag @conn.request_path, method: :get, id: "torch-filters-form" do %>
        <%= for {key, type} <- schema.attrs, type in [:string, :text] do %>
          <div class="field">
            <label><%= Phoenix.Naming.humanize(Atom.to_string(key)) %></label>
            <%%= filter_select(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
            <%%= filter_string_input(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
          </div>
        <% end %>
        <%= for {key, type} <- schema.attrs, type in [:boolean] do %>
          <div class="field">
            <label><%= Phoenix.Naming.humanize(Atom.to_string(key)) %></label>
            <%%= filter_boolean_input(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
          </div>
        <% end %>
        <%= for {key, type} <- schema.attrs, type in [:date, :datetime, :utc_datetime, :naive_datetime] do %>
          <div class="field">
            <label><%= Phoenix.Naming.humanize(Atom.to_string(key)) %></label>
            <%%= filter_date_input(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
          </div>
        <% end %>
        <%= for {key, type} <- schema.attrs, type in [:number, :integer] do %>
          <div class="field">
            <label><%= Phoenix.Naming.humanize(Atom.to_string(key)) %></label>
            <%%= number_filter_select(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
            <%%= filter_number_input(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
          </div>
        <% end %>
        <%= for {key, type} <- schema.attrs, type in [:binary_id] do %>
          <div class="field">
            <label><%= Phoenix.Naming.humanize(Atom.to_string(key)) %></label>
            <%%= filter_uuid(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
            <%%= filter_string_input(:<%= schema.singular %>, :<%= key %>, @conn.params) %>
          </div>
        <% end %>
        <button type="submit" class="torch-button">Search</button>
        <%%= link "Clear Filters", to: ~p"<%=  schema.route_prefix %>" %>
      <%% end %>

    </section>

    <section id="torch-table">
    <%%= if length(@<%= schema.plural %>) > 0 do %>
      <table>
        <thead>
          <tr>
            <%= for {k, _} <- schema.attrs do %>
              <th><%%= table_link(@conn, "<%= Phoenix.Naming.humanize(Atom.to_string(k)) %>", <%= inspect(k) %>) %></th>
            <% end %>
            <th><span>Actions</span></th>
          </tr>
        </thead>
        <tbody>
          <%%= for <%= schema.singular %> <- @<%= schema.plural %> do %>
            <tr>
              <%= for {k, _} <- schema.attrs do %>
                <td><%%= <%= schema.singular %>.<%= k %> %></td>
              <% end %>
              <td class="torch-actions">
                <span><.link href={~p"<%= schema.route_prefix %>/#{<%= schema.singular %>}"}><%%= Torch.I18n.message("Show") %></.link></span>
                <span><.link href={~p"<%= schema.route_prefix %>/#{<%= schema.singular %>}/edit"}><%%= Torch.I18n.message("Edit") %></.link></span>
                <span><.link href={~p"<%= schema.route_prefix %>/#{<%= schema.singular %>}"} method="delete" data-confirm={Torch.I18n.message("Are you sure?")}><%%= Torch.I18n.message("Delete") %></.link></span>
              </td>
            </tr>
          <%% end %>
        </tbody>
      </table>
      <%%= Torch.PaginationView.pagination(@conn) %>
    <%% else %>
      <p class="torch-no-data">No <%= schema.human_plural %> match your search.</p>
    <%% end %>
    </section>
  </div>
</section>
